package wli.web.util;
import java.util.*;

public class MyHtmlDisplay {
    public static String arrayListToTable(ArrayList a, int columns)
    {
	StringBuffer sbf = new StringBuffer();
	Iterator it = a.iterator();
	int n=0;
	sbf.append("\n<TABLE width=100% cellSpacing='2' cellPadding='2' border='0'>\n<TR>");
	while(it.hasNext()) {
	    n++;
	    sbf.append("<TD style='BORDER: 1px solid;'>"+it.next()+"</TD>");
	    if(n%columns==0) {
		sbf.append("</TR>");
		if(n<a.size()) {
		    sbf.append("\n<TR>");
		}
	    }
	}
	if(n%columns != 0 && columns>1){
	    for(int j=0; j<(columns-n%columns);j++) {
		sbf.append("<TD style='BORDER: 1px solid;'>&nbsp;</TD>");
	    }
	    sbf.append("</TR>");
	}
	sbf.append("</TABLE>");
	return sbf.toString();
    }

    public static String textToHtml(String s)
    {
	if(s.length()<1) {
	    return "";
	}

	if(s.startsWith(" ")) {
	    s = "&nbsp;"+s;
	}
	else {
	    if(s.length()>1 && !s.startsWith("&nbsp;")) {
		s = "&nbsp;    "+s;
	    }
	}
	return "<blockquote><p>"+s+"</p></blockquote>";
    }

    public static String textToList(String s, String dim)
    {
	if(s.length()<1) {
	    return "";
	}
	if(s.indexOf(dim) != -1){
	    s = s.replaceAll(dim,"<LI></LI>");
	}
	return "<UL><LI>"+s+"</LI></UL>";
    }
}


